package com.szh.cloud.spring.security;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

@Component
public class GdmtPasswordEncoder implements PasswordEncoder {

    @Value("${passwd.key}")
    private String passwdKey;
    @Override
    public String encode(CharSequence charSequence) {//加密
        return DigestUtils.md5DigestAsHex((charSequence.toString() + passwdKey).getBytes());
    }


    public boolean matches(CharSequence chaOverriderSequence, String s) {
        if(chaOverriderSequence == null){
            return false;
        }

        if(s == null){
            return false;
        }
        String srcString = encode(chaOverriderSequence);
        return s.equals(srcString);
    }
}
